<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('会议申请')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: select2-js" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <input type="text" name="meetingName" placeholder="请输入会议名称"/>
                            </li>
                            <li>
                                <div class="col-sm-9">
<!--                                    <select class="form-control">-->
<!--                                        <option th:each="post:${deptList}" th:value="${post.deptId}" th:text="${post.deptName}" th:disabled="${post.status == '1'}" ></option>-->
<!--                                    </select>-->
                                    <select class="form-control" id="deptIdList" name="deptId">
                                        <option value="">请选择部门</option>
                                        <!--                        <option th:each="post:${deptList}" th:value="${post.deptId}" th:text="${post.deptName}" th:disabled="${post.status == '1'}" ></option>-->
                                    </select>
                                </div>
                            </li>
                            <li>
                                <select name="status" class="form-control">
                                    <option value="">请选择状态</option>
                                    <option value="0">未开始</option>
                                    <option value="1">进行中</option>
                                    <option value="2">已结束</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
<!--            新增会议纪要的表单-->
<!--            <div id="addMeetingRecord" class="modal fade" role="dialog">-->
<!--                <div class="modal-dialog">-->
<!--                    <div class="modal-header">-->
<!--                        <h4 class="modal-title">新增会议纪要</h4>-->
<!--                        <button type="button" class="close" data-dismiss="modal">x</button>-->
<!--                    </div>-->
<!--                    <div class="modal-body">-->

<!--                        <form id="addRecordForm">-->

<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">编号</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="id" class="form-control" placeholder="保存后自动生成" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">名称:</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="meetingName" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">创建人</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="createPerson" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label"> 创建时间</label>\-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="createTime" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">紧急程度:</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="level" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">部门:</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="deptId" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">地点</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="addressId" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">主持人</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="hostId" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">联系人</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="linkmanId" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">联系方式</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="phoneNumber" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">开始时间</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="startTime" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">结束时间</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="endTime" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">与会人</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="meetingPerson" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">分享人</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="sharedPerson" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">类型</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="type" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">附件</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="context" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">备注</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <input type="text" name="notes" class="form-control" readonly>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-3 control-label">会议纪要</label>-->
<!--                                <div class="col-sm-9">-->
<!--                                    <textarea name="meetingRecord" class="form-control">[[*{meetingRecord}]]</textarea>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                        </form>-->
<!--                        <div class="modal-footer">-->
<!--                            <button type="button" class="btn btn-primary" onclick="submitMeetingRecordApply()">提交</button>-->
<!--                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="list:application:add">
                    <i class="fa fa-plus"></i> 会议发起
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="meeting:manager:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="list:application:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('list:application:edit')}]];
        var detailFlag = [[${@permission.hasPermi('list:application:detail')}]];
        var removeFlag = [[${@permission.hasPermi('list:application:remove')}]];
        var prefix = ctx + "list/application";
        var tmdMeetingStatus = [[${@dict.getType('tmd_meeting_application_status')}]];


        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                minutesUrl: prefix + "/minutes/{id}",
                modalName: "会议列表",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '编号',
                    visible: false,
                },
                    {
                        title: "编号",
                        formatter: function (value, row, index) {
                            return $.table.serialNumber(index);
                        },
                        align: 'center',
                    },
                {
                    field: 'meetingName',
                    title: '会议名称',
                    visible: true,
                    align: 'center',
                },
                {
                    field: 'addressName',
                    title: '地点',
                    align: 'center',
                    visible: true,
                },
                {
                    field: 'deptName',
                    title: '所属部门',
                    align: 'center',
                    visible: true,
                },
                {
                    field: 'createPerson',
                    title: '创建人',
                    align: 'center',
                    visible: true,
                },
                {
                    field:'createTime',
                    align: 'center',
                    title: '创建时间',
                },
                {
                    field: 'status',
                    title: '状态',
                    align: 'center',
                    formatter: function (value) {
                        return $.table.selectDictLabel(tmdMeetingStatus, value);
                    },
                    visible: true,
                },
                {
                    field: 'level',
                    title: '紧急程度',
                    align: 'center',
                    visible: false,
                },
                {
                    field: 'hostId',
                    title: '主持人',
                    visible: false,
                    align: 'center',
                },
                {
                    field: 'linkmanId',
                    title: '联系人',
                    visible: false,
                    align: 'center',
                },
                {
                    field: 'startTime',
                    title: '开始时间',
                    visible: false,
                    align: 'center',
                },
                {
                    field: 'endTime',
                    title: '结束时间',
                    visible: false,
                    align: 'center',
                },
                {
                    field: 'type',
                    title: '类型',
                    visible: false,
                    align: 'center',
                },
                {
                    field: 'file',
                    title: '附件',
                    visible: false,
                    align: 'center',
                },
                {
                    field: 'context',
                    title: '内容',
                    visible: false,
                    align: 'center',
                },
                {
                    field: 'notes',
                    title: '备注',
                    visible: false,
                    align: 'center',
                },
                {
                    field: 'meetingRecord',
                    title: '会议纪要',
                    visible: false,
                    align: 'center',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        //查看按钮
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-comments"></i>查看</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>修改</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        //开始
                        if (row.status === 0){
                            actions.push('<a class="btn btn-success btn-xs"  href="javascript:void(0)" onclick = "beginning(\'' + row.id+','+row.status + '\')"  id="start '+ row.id + '"  ><i class="fa fa-edit"></i>开始</a> ');
                        }else if(row.status === 1 || row.status === 2){
                            actions.push('<a class="btn btn-success btn-xs"  href="javascript:void(0)" disabled="true" onclick = "beginning(\'' + row.id + '\')"  id="start '+ row.id + '"  ><i class="fa fa-edit"></i>开始</a> ');
                        }
                        //结束

                        if (row.status === 1){
                            actions.push('<a class="btn btn-danger btn-xs"  href="javascript:void(0)" onclick = "endless(\'' + row.id + ','+row.status + '\')"  id="over '+ row.id + '"  ><i class="fa fa-edit"></i>结束</a> ');
                        }else if(row.status === 2 || row.status === 0){
                            actions.push('<a class="btn btn-success btn-xs"  href="javascript:void(0)" disabled="true" onclick = "endless(\'' + row.id + '\')"  id="over '+ row.id + '"  ><i class="fa fa-edit"></i>结束</a> ');
                        }
                        return actions.join('');
                    }
                },
                    {
                        title: '会议纪要',
                        formatter: function (value, row, index) {
                            if(row.status==2){
                                if(row.meetingRecord == null ||row.meetingRecord == ''){
                                    return '<a style="background-color: #006400" class="btn btn-success btn-xs ' + editFlag + '" href=" " onclick="$.operate.minutes(\'' + row.id + '\')">新增纪要</a > '
                                }else {
                                    return '<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.minutes(\'' + row.id + '\')">查看纪要</a > '
                                }
                            }else {
                                return '<a style="background-color: #696969" class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)">暂无纪要</a > '
                            }
                        }
                    }]
            };
            $.table.init(options);
        });
        function beginning(str){
            var arr=str.split(',');
            if (arr[1] === '0'){
                $.ajax({
                    type: "POST",
                    url: prefix + "/beginning",
                    data: {
                        id: arr[0]
                    },
                    success:function(response){
                        alert(response.msg);
                        location.reload();
                    },
                    error:function(xhr,status,error){
                        alert('会议开始失败'+xhr.respnseText)
                    }
                })
            }

        }
        function endless(str){
            var arr=str.split(',');
            if (arr[1] === '1'){
                $.ajax({
                    type: "POST",
                    url: prefix + "/endless",
                    data: {
                        id: arr[0]
                    },
                    success:function(response){
                        alert('会议结束');
                        location.reload();
                    },
                    error:function(xhr,status,error){
                        alert('会议结束失败'+xhr.respnseText)
                    }
                })
            }
        }
        $(document).ready(function(){
            $.ajax({
                url: prefix + '/getDeptList',
                type: 'GET',
                dataType: 'json',
                success:function (response){
                    //获取用户列表填充到下拉框中
                    var userList = response.rows;
                    var selectElement = $('#deptIdList');
                    $.each(userList,function(index,user){
                        selectElement.append($('<option>',{
                            value: user.deptId,
                            text: user.deptName
                        }));
                    });
                },
                error: function(xhr,status,error){
                    console.error('错误',error)
                }
            })
        })
    </script>
<!--    <script>-->
<!--        function submitMeetingRecordApply(){-->
<!--            if($.validate.form()){-->
<!--                $.operate.save(prefix + "/apply",$('#addRecordForm'));-->
<!--            }-->
<!--        }-->
<!--        //清除 模态框中的文本框值-->
<!--            $('#addMeetingRecord').on('hidden.bs.modal', function () {-->
<!--               $(this).find('input[type = text],select').val('');-->
<!--            });-->
<!--    </script>-->
<!--    <script>-->
<!--        function applyForMeeting(){-->
<!--            $.ajax({-->
<!--                url: prefix + "/getMeetingRecord" + id,-->
<!--                type: "GET",-->
<!--                dataType:'json',-->
<!--                success: function (response) {-->
<!--                    if (response.code === 0){-->
<!--                        // $('#carCard').val(response.data.meetingName)-->
<!--                        // $('#carCard').attr('readonly',true)-->
<!--                        $('#addMeetingRecord').modal('show');-->
<!--                    }else{-->
<!--                        console.log('错误');-->
<!--                    }-->
<!--                },-->
<!--                error: function(){-->
<!--                    console.log('错误')-->
<!--                }-->
<!--            });-->
<!--        }-->

<!--    </script>-->
</body>
</html>